// Copyright 叶湘 ( weixin:yexiang841, email:yexiang841@qq.com ), Shitouren Studio. All Rights Reserved.

#include "Pawn/Q3D_CPPA_Pawn_FighterChief_ClassA.h"
#include "Logger/Q3D_CPPU_Logger.h"

AQ3D_CPPA_Pawn_FighterChief_ClassA::AQ3D_CPPA_Pawn_FighterChief_ClassA()
{
    // set our turn rates for input
    BaseTurnRate = 15.f;
}

// Called when the game starts or when spawned
void AQ3D_CPPA_Pawn_FighterChief_ClassA::BeginPlay()
{
    Super::BeginPlay();

    // 基类的 BeginPlay() 通过调用本类的 Q3D_IF_PropertyState_InitDT_Get() 向 PropertyState 中写入了初始数据

    // 绑定一些属性关联
    this->Ptr_C_PropertyState->Q3D_F_Property_Bind_Max_To_Now(EQ3D_CPPE_PropertyName::LIVE_HP_MAX, EQ3D_CPPE_PropertyName::LIVE_HP_NOW);
    this->Ptr_C_PropertyState->Q3D_F_Property_Bind_Max_To_Now(EQ3D_CPPE_PropertyName::MANA_MP_MAX, EQ3D_CPPE_PropertyName::MANA_MP_NOW);
    this->Ptr_C_PropertyState->Q3D_F_Property_Bind_Max_To_Now(EQ3D_CPPE_PropertyName::ENERGY_STA_MAX, EQ3D_CPPE_PropertyName::ENERGY_STA_NOW);

    // 新增一些自然回复
    float float_hit_interval = 0.5f;
    UQ3D_CPPU_Hit *ptr_u_hit;
    this->Ptr_C_PropertyState->Q3D_F_Create_Hit_On_Now_By_Spd(EQ3D_CPPE_PropertyName::MANA_MP_SPD, EQ3D_CPPE_PropertyName::MANA_MP_NOW, float_hit_interval, ptr_u_hit);
    this->Ptr_C_PropertyState->Q3D_F_Create_Hit_On_Now_By_Spd(EQ3D_CPPE_PropertyName::LIVE_HP_SPD, EQ3D_CPPE_PropertyName::LIVE_HP_NOW, float_hit_interval, ptr_u_hit);
    this->Ptr_C_PropertyState->Q3D_F_Create_Hit_On_Now_By_Spd(EQ3D_CPPE_PropertyName::ENERGY_STA_SPD, EQ3D_CPPE_PropertyName::ENERGY_STA_NOW, float_hit_interval, ptr_u_hit);
}

void AQ3D_CPPA_Pawn_FighterChief_ClassA::Q3D_IF_PropertyState_InitDT_Get_Implementation(UDataTable *&ptr_dt_property_init) const
{
    // Owner 已经从外部对 Ptr_DT_PropertyInit 进行了赋值，优先级最高，直接使用
    if (this->Ptr_DT_PropertyInit)
    {
        ptr_dt_property_init = this->Ptr_DT_PropertyInit;
        Q3D_LOG(Log, "DT_Load_From_Ptr_DT_PropertyInit");
        return;
    }

    // 子类未赋值DT，就用默认的
    const FString string_dt_path_tmp = "DataTable'/Q3D_Lib/Q3D/Property/Q3D_DT_Property_Pawn_FighterChief_ClassA.Q3D_DT_Property_Pawn_FighterChief_ClassA'";

    // 结构体
    // EQ3D_CPPE_PropertyName Enum_PropertyName;
    // bool Bool_Active;
    // int32 Int_Min;
    // int32 Int_Max;
    // EQ3D_CPPE_PropertyInit Enum_PropertyInit;
    // int32 Int_Value;

    UDataTable *ptr_dt_property_init_tmp;

    // DT的一种读法
    // static ConstructorHelpers::FObjectFinder<UDataTable> finder_tmp( string_dt_path_tmp );
    // if( finder_tmp.Object ){ ptr_dt_property_init_tmp = ( UDataTable* )( finder_tmp.Object ); }

    // DT的另一种读法
    ptr_dt_property_init_tmp = LoadObject<UDataTable>(NULL, UTF8_TO_TCHAR(*string_dt_path_tmp));

    if (!ptr_dt_property_init_tmp)
    {
        Q3D_LOG(Warning, "DT_Missed_From_[" + string_dt_path_tmp + "]");
        ptr_dt_property_init = nullptr;
        return;
    }
    ptr_dt_property_init = ptr_dt_property_init_tmp;
    Q3D_LOG(Log, "DT_Load_From_[" + string_dt_path_tmp + "]");
    return;
}

void AQ3D_CPPA_Pawn_FighterChief_ClassA::SetupPlayerInputComponent(class UInputComponent *PlayerInputComponent)
{
    // Set up gameplay key bindings
    check(PlayerInputComponent);

    // handle touch devices
    PlayerInputComponent->BindTouch(IE_Pressed, this, &AQ3D_CPPA_Pawn_FighterChief_ClassA::TouchStarted);
    PlayerInputComponent->BindTouch(IE_Released, this, &AQ3D_CPPA_Pawn_FighterChief_ClassA::TouchStopped);

    // VR headset functionality
    PlayerInputComponent->BindAction("ResetVR", IE_Pressed, this, &AQ3D_CPPA_Pawn_FighterChief_ClassA::OnResetVR);
}

void AQ3D_CPPA_Pawn_FighterChief_ClassA::TouchStarted(ETouchIndex::Type FingerIndex, FVector Location)
{
}

void AQ3D_CPPA_Pawn_FighterChief_ClassA::TouchStopped(ETouchIndex::Type FingerIndex, FVector Location)
{
}

void AQ3D_CPPA_Pawn_FighterChief_ClassA::OnResetVR()
{
    // If TP_ThirdPerson is added to a project via 'Add Feature' in the Unreal Editor the dependency on HeadMountedDisplay in TP_ThirdPerson.Build.cs is not automatically propagated
    // and a linker error will result.
    // You will need to either:
    //		Add "HeadMountedDisplay" to [YourProject].Build.cs PublicDependencyModuleNames in order to build successfully (appropriate if supporting VR).
    // or:
    //		Comment or delete the call to ResetOrientationAndPosition below (appropriate if not supporting VR)
    // UHeadMountedDisplayFunctionLibrary::ResetOrientationAndPosition();
}
